PRO=/home/duyq/workspace/minios
BOOT=$(PRO)/boot
BIN=$(PRO)/bin
HD=$(PRO)/hd60M.img
INCLUDE=$(BOOT)/include/


run:mbr.bin loader.bin kernel.bin
	dd if=$(BIN)/mbr.bin of=$(HD) bs=512 count=1 conv=notrunc;
	dd if=$(BIN)/loader.bin of=$(HD) bs=512 count=4 seek=2 conv=notrunc;
	dd if=$(BIN)/kernel.bin of=$(HD) bs=512 count=200 seek=9 conv=notrunc;
	rm -f $(BIN)/*;
	bochs -f $(PRO)/bochsrc.disk;
	
mbr.bin:
	nasm -I $(INCLUDE) -o  $(BIN)/mbr.bin   $(BOOT)/mbr.s;

loader.bin:
	nasm -I $(INCLUDE) -o  $(BIN)/loader.bin $(BOOT)/loader.s;

hd60M.img:
	dd if=$(PRO)/boot/mbr.bin of=$(PRO)/hd60M.img bs=512 count=1 conv=123

print.o:
	nasm -f elf32 -o $(BIN)/kernel_print.o $(PRO)/lib/kernel/print.s;

main.o:
	gcc -m32 -I $(PRO)/lib/kernel/ -I $(PRO)/lib/  -c -o $(BIN)/kernel_main.o $(PRO)/kernel/main.c;

kernel.bin: main.o print.o
	ld -m elf_i386 -Ttext 0xc0001500 -e main -o $(BIN)/kernel.bin  $(BIN)/kernel_main.o  $(BIN)/kernel_print.o;




# the target blow write for testing


test.bin:
	gcc -o $(PRO)/bin/test.bin  $(PRO)/kernel/main.c


header.bin:
	nasm -o $(PRO)/bin/header.bin     $(PRO)/code/test/chapt5/header.s


# xxd -u -a -g 1 -s $2 -l $3 $

# gcc -c -o kernel/main.o kernel/main.c 
# ld kernel/main.o -Ttext 0xC0001500 -e main -o kernel/kernel.bin